home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / network / manageme / tcpdump-.001 / tcpdump-~ / tcpdump-3.0.2-linux / tcpdump-3.0.2 / print-rip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-15  |  3.3 KB  |  118 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991, 1993, 1994
  3.  *    The Regents of the University of California.  All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that: (1) source code distributions
  7.  * retain the above copyright notice and this paragraph in its entirety, (2)
  8.  * distributions including binary code include the above copyright notice and
  9.  * this paragraph in its entirety in the documentation or other materials
  10.  * provided with the distribution, and (3) all advertising materials mentioning
  11.  * features or use of this software display the following acknowledgement:
  12.  * ``This product includes software developed by the University of California,
  13.  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14.  * the University nor the names of its contributors may be used to endorse
  15.  * or promote products derived from this software without specific prior
  16.  * written permission.
  17.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20.  */
  21.  
  22. #ifndef lint
  23. static char rcsid[] =
  24.     "@(#) $Header: print-rip.c,v 1.20 94/06/14 20:18:47 leres Exp $ (LBL)";
  25. #endif
  26.  
  27. #include <sys/param.h>
  28. #include <sys/time.h>
  29. #include <sys/types.h>
  30. #include <sys/socket.h>
  31.  
  32. #include <netinet/in.h>
  33. #include <netinet/in_systm.h>
  34. #include <netinet/ip.h>
  35. #include <netinet/ip_var.h>
  36. #include <netinet/udp.h>
  37. #include <netinet/udp_var.h>
  38.  
  39. #include <protocols/routed.h>
  40.  
  41. #include <errno.h>
  42. #include <stdio.h>
  43.  
  44. #include "interface.h"
  45. #include "addrtoname.h"
  46.  
  47. static void
  48. rip_entry_print(register const struct netinfo *ni)
  49. {
  50.     if (ntohs(ni->rip_dst.sa_family) != AF_INET) {
  51.         register int i;
  52.  
  53.         printf(" [family %d:", ntohs(ni->rip_dst.sa_family));
  54.         for (i = 0; i < 14; i += 2)
  55.             printf(" %02x%02x", (u_char)ni->rip_dst.sa_data[i],
  56.                 (u_char)ni->rip_dst.sa_data[i+1]);
  57.         printf("]");
  58.     } else {
  59.         register struct sockaddr_in *sin =
  60.                 (struct sockaddr_in *)&ni->rip_dst;
  61.         printf(" %s", ipaddr_string(&sin->sin_addr));
  62.         if (sin->sin_port)
  63.             printf(" [port %d]", sin->sin_port);
  64.     }
  65.     printf("(%d)", ntohl(ni->rip_metric));
  66. }
  67.  
  68. void
  69. rip_print(const u_char *dat, int length)
  70. {
  71.     register const struct rip *rp = (struct rip *)dat;
  72.     register const struct netinfo *ni;
  73.     register int amt = snapend - dat;
  74.     register int i = min(length, amt) -
  75.              (sizeof(struct rip) - sizeof(struct netinfo));
  76.     int j;
  77.     int trunc;
  78.  
  79.     if (i < 0)
  80.         return;
  81.  
  82.     switch (rp->rip_cmd) {
  83.  
  84.     case RIPCMD_REQUEST:
  85.         printf(" rip-req %d", length);
  86.         break;
  87.     case RIPCMD_RESPONSE:
  88.         j = length / sizeof(*ni);
  89.         if (j * sizeof(*ni) != length - 4)
  90.             printf(" rip-resp %d[%d]:", j, length);
  91.         else
  92.             printf(" rip-resp %d:", j);
  93.         trunc = ((i / sizeof(*ni)) * sizeof(*ni) != i);
  94.         for (ni = rp->rip_nets; (i -= sizeof(*ni)) >= 0; ++ni)
  95.             rip_entry_print(ni);
  96.         if (trunc)
  97.             printf("[|rip]");
  98.         break;
  99.     case RIPCMD_TRACEON:
  100.         printf(" rip-traceon %d: \"%s\"", length, rp->rip_tracefile);
  101.         break;
  102.     case RIPCMD_TRACEOFF:
  103.         printf(" rip-traceoff %d", length);
  104.         break;
  105.     case RIPCMD_POLL:
  106.         printf(" rip-poll %d", length);
  107.         break;
  108.     case RIPCMD_POLLENTRY:
  109.         printf(" rip-pollentry %d", length);
  110.         break;
  111.     default:
  112.         printf(" rip-%d ?? %d", rp->rip_cmd, length);
  113.         break;
  114.     }
  115.     if (rp->rip_vers != RIPVERSION)
  116.         printf(" [vers %d]", rp->rip_vers);
  117. }
  118.